package com.qzuser.sendmessagebasic.demo;

import com.qzuser.sendmessagebasic.client.Channel;
import com.qzuser.sendmessagebasic.client.Connection;
import com.qzuser.sendmessagebasic.client.ConnectionFactory;

public class Consumer {
    public static void main(String[] args) throws InterruptedException {
        ConnectionFactory cf = new ConnectionFactory();
        cf.setHost("127.0.0.1");
        cf.setPort(9999);
        Connection connection = cf.createConnection();
        Channel channel = connection.createChannel();
        channel.basicConsume("queue", true, (tag, pro, body) -> {
            System.out.println("[消费数据]开始!");
            System.out.println("consumerTag = " + tag);
            System.out.println(pro);
            String bodyString = new String(body, 0, body.length);
            System.out.println("message = " + bodyString);
            System.out.println("[消费数据] 结束!");
        });
        while(true) {
            Thread.sleep(50);
        }
    }
}
